package com.apeli;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.SneakyThrows;
import lombok.experimental.FieldDefaults;
import org.springframework.context.ApplicationEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.EventListener;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;


@Component
public class OrderApplicationListener  {


    @SneakyThrows
    @Async
    @EventListener
    public void onApplicationEvent(OrderEvent event) {
        Thread.sleep(5000);
        System.out.println("接收到了消息:==> 消息id" + event.msgId +"消息内容："+event.name+event.getSource());
    }

    public static class OrderEvent extends ApplicationEvent {
        private String name;

        private String msgId;

        public OrderEvent(Object resource,String name,String msgId) {
            super(resource);
            this.name = name;
            this.msgId = msgId;
        }

        public OrderEvent(Object source) {
            super(source);
        }
    }
}
